from django import forms
from django.forms import flatatt
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe

__author__ = 'Sea'

class ImageFileInput(forms.FileInput):
    def render(self, name, value, attrs=None):
        if value is None:
            value = ''
        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
        if value != '':
            # Only add the 'value' attribute if a value is non-empty.
            final_attrs['value'] = force_unicode(self._format_value(value))
        return mark_safe(u'<input%s />' % flatatt(final_attrs))

class ImageUploadedProgressFileInput(forms.FileInput):
    UPLOADED_PROGRESS_FIELD_NAME = 'iUploadedProgress'
